Line following BubbleRob <<
Previous Next >> Simulation
External controller tutorial
由40723210提供
在CoppeliaSim中,有幾種方法可以控制機器人或仿真:
- The most convenient way is to write a child script that will handle the behaviour of a given robot or model. It is the most convenient way, because child scripts are directly attached to scene objects, they will be duplicated together with their associated scene objects, they do not need any compilation with an external tool, they can run in threaded or non-threaded mode, they can be extended via custom Lua function or via a Lua extension library. Another major advantage in using child scripts: there is no communication lag as with the last 3 methods mentioned in this section (i.e. the regular API is used), and child scripts are part of the application main thread (inherent synchronous operation). There are several drawback to writing scripts however: you don't have the choice of the programming language, you can't have the fastest code, and you can't directly access external function libraries, except the Lua extension libraries.
- 最方便的方法是編寫一個子腳本,以處理給定機器人或模型的行為。這是最便捷的方式,因為孩子的腳本直接連接到場景中的對象,他們將與它們相關的場景對象進行複製,他們不需要任何編譯與外部的工具,它們可以在運行線程還是非線程模式,可以通過自定義Lua函數或Lua擴展庫對其進行擴展。使用子腳本的另一個主要優點:與本節中提到的後三種方法(即常規API)一樣,沒有通信延遲,並且子腳本是應用程序主線程的一部分(固有的同步操作)。但是,編寫腳本有幾個缺點:您無法選擇編程語言,不能擁有最快的代碼,並且除了Lua擴展庫之外,您無法直接訪問外部函數庫。
- Another way one can control a robot or a simulation is by writing a plugin. The plugin mechanism allows for callback mechanisms, custom Lua function registration, and of course access to external function libraries. A plugin is often used in conjunction with child scripts (e.g. the plugin registers custom Lua functions, that, when called from a child script, will call back a specific plugin function). A major advantage in using plugins is also that there is no communication lag as with the last 3 methods mentioned in this section (i.e. the regular API is used), and that a plugin is part of the application main thread (inherent synchronous operation). The drawbacks with plugins are: they are more complicated to program, and they need to be compiled with an external too. Refer also to the plugin tutorial.
- 可以控制機器人或模擬的另一種方法是編寫插件。插件機制允許回調機制,自定義Lua函數註冊,當然還可以訪問外部函數庫。插件通常與子腳本結合使用(例如,插件註冊自定義Lua函數,當從子腳本中調用時,該Lua函數將回調特定的插件函數)。使用插件的一個主要優點是,與本節中提到的後3種方法(即常規API)一樣,沒有通信延遲(使用),並且插件是應用程序主線程的一部分(固有的同步操作)。插件的缺點是:它們的編程更加複雜,並且也需要使用外部編譯。另請參閱插件教程。
- A third and forth way one can control a robot or a simulation is by writing an external client application that relies on the remote API. This is a very convenient and easy way, if you need to run the control code from an external application, from a robot or from another computer. This also allows you to control a simulation or a model (e.g. a virtual robot) with the exact same code as the one that runs the real robot. The remote API comes in two versions: the B0-based remote API, and the legacy remote API.
- 控制機器人或模擬的第三種方式是編寫依賴於遠程API的外部客戶端應用程序。如果您需要從外部應用程序,機器人或另一台計算機運行控制代碼,這是一種非常便捷的方法。這還允許您使用與運行真實機器人完全相同的代碼來控制仿真或模型(例如,虛擬機器人)。遠程API有兩個版本:基於B0的遠程API和舊版遠程API。
- A fifth way to control a robot or a simulation is via a ROS node. In a similar way as the remote API, ROS is a convenient way to have several distributed processes communicate with each other. While the remote API is very lightweight and fast, it allows only communication with CoppeliaSim. ROS on the other hand allows connecting virtually any number of processes with each other, and a large amount of compatible libraries are available. It is however heavier and more complicated than the remote API. Refer to the ROS interfaces for details.
- 控制機器人或仿真的第五種方法是通過ROS節點。ROS 與遠程API相似,是使多個分佈式進程相互通信的便捷方法。儘管遠程API非常輕巧且快速,但它僅允許與CoppeliaSim通信。另一方面,ROS允許幾乎將任意數量的進程相互連接,並且提供了大量兼容的庫。但是,它比遠程API重並且更複雜。有關詳細信息,請參閱ROS接口。
- A sixth way to control a robot or a simulation is via a BlueZero (BØ) node. In a similar way as ROS, BlueZero is a convenient way to have several distributed processes communicate with each other, and is a lightweight and cross-platform solution. Refer to the BlueZero interface for details.
- 控制機器人或模擬的第六種方法是通過BlueZero(BØ)節點。與ROS類似,BlueZero是使多個分佈式進程相互通信的一種便捷方法,並且是一種輕量級的跨平台解決方案。有關詳細信息,請參考BlueZero界面。
- A seventh way to control a robot or a simulation is by writing an external application that communicates via various means (e.g. pipes, sockets, serial port, etc.) with a CoppeliaSim plugin or CoppeliaSim script. Two major advantages are the choice of programming language, which can be just any language, and the flexibility. Here also, the control code can run on a robot, or a different computer. This way of controlling a simulation or a model is however more tedious that the methods with the remote API.
- 控制機器人或模擬的第七種方法是編寫一個外部應用程序,該應用程序通過各種方式(例如管道,套接字,串行端口等)與CoppeliaSim插件或CoppeliaSim腳本進行通信。選擇編程語言(可以是任何一種語言)和靈活性是兩個主要優點。同樣,控制代碼也可以在機器人或其他計算機上運行。但是,與使用遠程API的方法相比,這種控制仿真或模型的方法更加乏味。
有8個與本教程相關的場景文件:
- scenes/controlTypeExamples/controlledViaScript: one robot is controlled via a non-threaded child script, the other is controlled via a threaded child script.
- scenes/controlTypeExamples/controlledViaPlugin: the robot is controlled via a plugin.
- scenes/controlTypeExamples/controlledViaB0RemoteApi: the robot is controlled via the B0-based remote API.
- scenes/controlTypeExamples/controlledViaLegacyRemoteApi: the robot is controlled via the legacy remote API.
- scenes/controlTypeExamples/controlledViaB0: the robot is controlled via the BlueZero interface.
- scenes/controlTypeExamples/controlledViaRos: the robot is controlled via the ROS interface.
- scenes/controlTypeExamples/controlledViaRos2: the robot is controlled via the ROS2 interface.
- scenes/controlTypeExamples/controlledViaTcp: the robot is controlled via LuaSocket and TCP.
- scenes/controlTypeExamples/controlledViaScript:一個機器人通過控制非螺紋子腳本,另一種是通過受控的螺紋子腳本。
- scenes/controlTypeExamples/controlledViaPlugin:機器人是通過插件控制的。
- scenes/controlTypeExamples/controlledViaB0RemoteApi:通過基於B0的遠程API來控制機器人。
- scenes/controlTypeExamples/controlledViaLegacyRemoteApi:通過舊版遠程API控制機器人。
- scenes/controlTypeExamples/controlledViaB0:通過BlueZero界面控制機器人。
- scenes/controlTypeExamples/controlledViaRos:通過ROS接口控制機器人。
- cenes/controlTypeExamples/controlledViaRos2:通過ROS2接口控制機器人。
- scenes/controlTypeExamples/controlledViaTcp:機器人是通過LuaSocket和TCP 控制的。

在所有8種情況下,都使用子腳本,主要是為了與外界建立鏈接(例如,啟動正確的客戶端應用程序,並將正確的對象句柄傳遞給它)。有兩種方法可以控制機器人,仿真程序或仿真程序本身:通過使用自定義腳本或加載項。但是,不建議將它們用於控制,而應在不運行模擬時將其用於處理功能。
例如,鏈接到場景控制的ViaB0RemoteApi.ttt中的機器人的子腳本具有以下主要任務:
作為另一個示例,鏈接到場景控制的ViaRos.ttt中的機器人的子腳本具有以下主要任務:
然而,作為另一個示例,鏈接到場景控制的ViaTcp.ttt中的機器人的子腳本具有以下主要任務:
- 搜索空閒的套接字連接端口
- 使用所選的連接端口作為參數啟動控制器應用程序(bubbleRobServer)
- 本地連接到控制器應用程序
- 在每次仿真過程中,將傳感器值發送到控制器,並從控制器讀取所需的電機值
- 在每次模擬過程中,將所需的電機值應用於機器人的關節
運行模擬,然後復制並粘貼機器人:您將看到重複的機器人將直接運行,因為附加的子腳本負責啟動各自外部應用程序的新實例,或調用適當的插件函數。
Line following BubbleRob <<
Previous Next >> Simulation